﻿using AdverseEventReportSystem.BLL;
using AdverseEventReportSystem.BLL.SchedulingSystem;
using AdverseEventReportSystem.Core;
using AdverseEventReportSystem.Utils;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Script.Serialization;

namespace AdverseEventReportSystem.Web.Areas.Scheduling.Controllers
{
    public class SchedulingListController : BaseController
    {
        // GET: Scheduling/SchedulingList
        public ActionResult Index()
        {
            DateTime startDate = DateTime.Now.AddDays(1 - Convert.ToInt32(DateTime.Now.DayOfWeek.ToString("d")));
            DateTime endDate = startDate.AddDays(6);
            ViewBag.StartDate = startDate.ToString("yyyy-MM-dd");
            ViewBag.EndDate = endDate.ToString("yyyy-MM-dd");
            ViewBag.CurrDepCode = loginUser.CurrDepCode;
            return View();
        }

        /// <summary>
        /// 排班列表
        /// </summary>
        /// <returns></returns>
        public ActionResult Search()
        {
            string startDate = WebUtils.GetString("startDate");
            string endDate = WebUtils.GetString("endDate");
            string departmentCode = WebUtils.GetString("departmentCode");
            if (string.IsNullOrEmpty(departmentCode)) departmentCode = loginUser.CurrDepCode;
            SchedulingSystemSoapClient service = new SchedulingSystemSoapClient();
            ResultHelperOfDataTable serviceResult = service.GetSchedulingRecord(DataConvert.StrToDateTime(startDate, DateTime.Now), DataConvert.StrToDateTime(endDate, DateTime.Now), departmentCode);
            DataTable dt = new DataTable();
            if (serviceResult.S)
            {
                dt = serviceResult.D;
            }
            var result = new { Rows = dt };
            return JsonDate(result);
        }
    }
}

